class Solution {
public:
    void flatten(TreeNode* root) {
       while(root)
       {
        if(root->left)
        {
          TreeNode*right=root->right;
           TreeNode*left=root->left;
           TreeNode*cur=left;
           while(cur->right)
           {cur=cur->right;}
           root->right=left;
           root->left=nullptr;
           cur->right=right;

         

        }
         
          root=root->right;



       }
    }
};class Solution {
public:
    int maxProduct(vector<int>& nums) {
    int m=nums.size();
    vector<int>big(m+1);
    vector<int>small(m+1);
    int ret=INT_MIN;
    big[0]=small[0]=1;
    for(int i=1;i<=m;i++)
    {

     big[i]=max(max(nums[i-1],big[i-1]*nums[i-1]),nums[i-1]*small[i-1]);
     small[i]=min(min(nums[i-1],nums[i-1]*big[i-1]),nums[i-1]*small[i-1]);
     ret=max(ret,big[i]);
    }

    return ret;

    }
};class Solution {
public:
    int longestCommonSubsequence(string s1, string s2) {
    int m=s1.size();
    int n=s2.size();
    int ret=0;
    vector<vector<int>>dp(m+1,vector<int>(n+1,0));
    for(int i=1;i<=m;i++)
       for(int j=1;j<=n;j++)
          {

           if(s1[i-1]==s2[j-1])
            {
              dp[i][j]=dp[i-1][j-1]+1;

            }
            else
            {dp[i][j]=max(dp[i-1][j],dp[i][j-1]);}
          // ret=max(ret,dp[i][j]);
          } 
    return dp[m][n];
    }
};